﻿namespace Shortcuts.ViewModels
{
    using Shortcuts.Commands;
    using Shortcuts.Common;
    using System;
    using System.Windows.Input;

    public class HomePageContext : System.ComponentModel.INotifyPropertyChanged
    {
        public HomePageContext()
        {
            WiFi = Settings.WiFi.Localized();
            AirplaneMode = Settings.AirplaneMode.Localized();
            Cellular = Settings.Cellular.Localized(); ;
            Bluetooth = Settings.Bluetooth.Localized();
            Lock = Settings.Lock.Localized();
            Location = Settings.Location.Localized(); 
            Title = "SHORTCUTS".Localized();
            Pin = "pin to start".Localized();
            Open = "open".Localized();

            foreach (var tile in Tiles.ActiveTiles)
            {
                switch (tile.Settings)
                {
                    case Settings.AirplaneMode:
                        AirplaneModePinCommand.IsEnabled = false;
                        break;
                    case Settings.Cellular:
                        CellularPinCommand.IsEnabled = false;
                        break;
                    case Settings.Bluetooth:
                        BluetoothPinCommand.IsEnabled = false;
                        break;
                    case Settings.WiFi:
                        WiFiPinCommand.IsEnabled = false;
                        break;
                    case Settings.Lock:
                        LockPinCommand.IsEnabled = false;
                        break;
                    case Settings.Location:
                        LocationPinCommand.IsEnabled = false;
                        break;
                }
            }
        }

        Command tileCommand;
        public ICommand TileCommand
        {
            get
            {
                if (tileCommand == null)
                {
                    tileCommand = new Command(obj =>
                    {
                        string str = (string)obj;
                        Settings settings = (Settings)Enum.Parse(typeof(Settings), str, true);
                        settings.ToTile().Launch();
                    });
                }

                return tileCommand;
            }
        }

        Command wifiPinCommand;
        public Command WiFiPinCommand
        {
            get
            {
                if (wifiPinCommand == null)
                {
                    wifiPinCommand = new Command(parar =>
                    {
                        WiFiPinCommand.IsEnabled = false;
                        new WiFi().Pin();
                    });
                }

                return wifiPinCommand;
            }
        }

        Command airplaneModePinCommand;
        public Command AirplaneModePinCommand
        {
            get
            {
                if (airplaneModePinCommand == null)
                {
                    airplaneModePinCommand = new Command(parar =>
                    {
                        airplaneModePinCommand.IsEnabled = false;
                        new AirplaneMode().Pin();
                    });
                }

                return airplaneModePinCommand;
            }
        }

        Command bluetoothPinCommand;
        public Command BluetoothPinCommand
        {
            get
            {
                if (bluetoothPinCommand == null)
                {
                    bluetoothPinCommand = new Command(parar =>
                    {
                        BluetoothPinCommand.IsEnabled = false;
                        new Bluetooth().Pin();
                    });
                }

                return bluetoothPinCommand;
            }
        }

        Command cellularPinCommand;
        public Command CellularPinCommand
        {
            get
            {
                if (cellularPinCommand == null)
                {
                    cellularPinCommand = new Command(parar =>
                    {
                        CellularPinCommand.IsEnabled = false;
                        new Cellular().Pin();
                    });
                }

                return cellularPinCommand;
            }
        }

        Command lockPinCommand;
        public Command LockPinCommand
        {
            get
            {
                if (lockPinCommand == null)
                {
                    lockPinCommand = new Command(parar =>
                    {
                        lockPinCommand.IsEnabled = false;
                        new Lock().Pin();
                    });
                }

                return lockPinCommand;
            }
        }

        Command locationPinCommand;
        public Command LocationPinCommand
        {
            get
            {
                if (locationPinCommand == null)
                {
                    locationPinCommand = new Command(parar =>
                    {
                        locationPinCommand.IsEnabled = false;
                        new Location().Pin();
                    });
                }

                return locationPinCommand;
            }
        }

        #region properties

        public string WiFi { get; set; }

        public string AirplaneMode { get; set; }

        public string Bluetooth { get; set; }

        public string Cellular { get; set; }

        public string Lock { get; set; }

        public string Location { get; set; }

        public string Title { get; set; }

        public string Pin { get; set; }

        public string Open { get; set; }

        #endregion

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
        void NotifyPropertyChanged(string property)
        {
            System.ComponentModel.PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new System.ComponentModel.PropertyChangedEventArgs(property));
            }
        }
    }
}
